package com.ryan.member.controller;

import com.ryan.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller//这里只是为了请求生成微信扫描二维码，所以不需要使用rest
@RequestMapping("/api/ucenter/wx")
public class WxLoginController {

    @Autowired
    private MemberService memberService;

    /**
     * 微信登陆生成二维码的接口
     * @return
     */
    @GetMapping("/login")
    public String getQrCode(){
        String url = memberService.getCode();
        return "redirect:" + url;
    }

    /**
     * 微信扫码登陆后的回调函数，也就是登陆成功后的页面
     * @param code
     * @param status
     * @return
     */
    @GetMapping("/callback")
    public String callback(String code, String status){
        String jwtToken = memberService.callback(code, status);
        return "redirect:http://localhost:8030?token=" + jwtToken;
    }

}
